package com.jbm.enterapplication.utlisclass

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.jbm.onehome.common.OHInterface
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

/**
 * Created by 家帮忙 on 2017/9/4.
 */
class HttpNet {
    private constructor()

    /**
     * 单例模式
     * 只初始化一次
     */
    companion object{//静态模块
      fun getInstans():HttpNet {
            return MyHttpNet.HTTPNET;
        }
      private object MyHttpNet{
        internal var HTTPNET=HttpNet()

      }

    }
    //获取服务链接调用接口使用
    fun getOhInter(): OHInterface {
        return OHInterface.getG_server()

    }
    /**
     * 加载图片
     */
    fun getLoadImage(context:Context,file:Int ,imagg:ImageView){
        Glide.with(context).load(file)
         .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(imagg);

    }

    /**
    * 防止每次调用接口和更新ui
     * 重复代码
     */
fun  <T>obsevice(observable:  Observable<T> ): Observable<T>  {
      return observable.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io())
    }

}